﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="page-container">
    <div class="page-content">
        <div class="ui-layout row" id="layout" style="height: 100%; width: 100%;">
            <div class="ui-layout-west  col-xs-2">
                <div class="west-Panel">
                    <div class="panel-Title">字典分类</div>
                    <div id="itemTree"></div>
                </div>
            </div>
            <div class="ui-layout-center  col-xs-10">
                <div class="center-Panel">
                    <div class="panel-Title">
                        字典数据 - <span id="titleinfo">未选择分类</span>
                    </div>
                    <div class="titlePanel">
                        <div class="title-search">
                            <table>
                                <tr>
                                    <td style="padding-left: 2px;">
                                        <input id="txt_keyword" type="text" class="form-control" placeholder="名称" style="width: 200px;" />
                                    </td>
                                    <td style="padding-left: 5px;">
                                        <a id="btn_search" class="btn btn-primary btn-sm"><i class="fa fa-search"></i>&nbsp;查询</a>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="toolbar">
                            <div class="btn-group">
                                <a id="replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                                <a id="add" authorize="yes" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                                <a id="edit" authorize="yes" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                                <a id="delete" authorize="yes" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                            </div>
                            <div class="btn-group">
                                <a id="itemstype" class="btn btn-default" onclick="btn_itemstype()"><i class="fa fa-tags"></i>&nbsp;字典分类</a>
                            </div>
                            <script>$('.toolbar').authorizeButton()</script>
                        </div>
                    </div>
                    <div class="gridPanel">
                        <table id="gridTable"></table>
                    </div>
                </div>

            </div>

        </div>
    </div>

</div>

<script type="text/javascript">
    var itemId;
    $(function () {
        treeView();
        gridList();
    });

    function treeView() {
        $("#itemTree").treeview({
            height: $.fn.getLayoutContentHeight() + 15,
            url: "/SystemManage/ItemsType/GetTreeJson",
            onnodeclick: function (item) {
                $("#txt_keyword").val('');
                $('#btn_search').trigger("click");
            }
        });
    }

    function gridList() {
        var $gridList = $("#gridTable");
        $gridList.jqGridEx({
            height: $.fn.getGridHeight(),
            colModel: [
                { label: "主键", name: "Id", hidden: true, key: true },
                { label: '名称', name: 'ItemName', width: 150, align: 'left' },
                { label: '编号', name: 'ItemCode', width: 150, align: 'left' },
                { label: '排序', name: 'SortCode', width: 80, align: 'center' },
                {
                    label: "默认", name: "IsDefault", width: 60, align: "center",
                    formatter: function (cellvalue) {
                        return cellvalue == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                {
                    label: '创建时间', name: 'CreatorTime', width: 80, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
                },
                {
                    label: "有效", name: "EnabledMark", width: 60, align: "center",
                    formatter: function (cellvalue) {
                        return cellvalue == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                { label: "备注", name: "Description", index: "Description", width: 200, align: "left", sortable: false }
            ]
        });
        $("#btn_search").click(function () {
            var id = $("#itemTree").getCurrentNode().id;
            if (!id) {
                return false;
            }
            $gridList.jqGrid('setGridParam', {
                url: "/SystemManage/ItemsData/GetGridJson",
                postData: { itemId: id, keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    //添加
    function btn_add() {
        if (!$("#itemTree").getCurrentNode()) {
            $.fn.modalMsg('请在左侧选择某一项！', "warning");
            return false;
        }
        var itemId = $("#itemTree").getCurrentNode().id;
        var itemName = $("#itemTree").getCurrentNode().text;
        $.fn.modalOpen({
            id: "Form",
            title: itemName + " > 新增字典",
            url: "/SystemManage/ItemsData/Form?itemId=" + itemId,
            width: "450px",
            height: "370px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    //编辑
    function btn_edit() {
        if (!$("#itemTree").getCurrentNode()) {
            $.fn.modalMsg('请在左侧选择某一项！', "warning");
            return false;
        }
        var itemName = $("#itemTree").getCurrentNode().text;
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            $.fn.modalOpen({
                id: "Form",
                title: itemName + " 》修改字典",
                url: "/SystemManage/ItemsData/Form?keyValue=" + keyValue,
                width: "450px",
                height: "370px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
    }
    //删除
    function btn_delete() {
        if (!$("#itemTree").getCurrentNode()) {
            $.fn.modalMsg('请在左侧选择某一项！', "warning");
            return false;
        }
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.fn.deleteForm({
                url: "/SystemManage/ItemsData/DeleteForm",
                param: { keyValue: keyValue },
                success: function () {
                    $("#gridTable").resetSelection();
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            $.fn.modalMsg('请选择需要删除的数据项！', "warning");
        }
    }
    //字典分类
    function btn_itemstype() {
        $.fn.modalOpen({
            id: "ItemsType",
            title: "字典分类",
            url: "/SystemManage/ItemsType/Index",
            width: "800px",
            height: "550px",
            btn: null,
        });
    }
</script>

